package com.bencordingley.remotecontrol;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

import com.bencordingley.remotecontrol.TouchInterceptor.DropListener;
import com.bencordingley.remotecontrol.TouchInterceptor.RemoveListener;

public class Playlists extends ListActivity implements DropListener, RemoveListener {
	
	ArrayAdapter<String> playlist;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.playlist);

		playlist = new ArrayAdapter<String>(this, R.layout.playlist_item, R.id.Text_filename, new ArrayList<String>());
		setListAdapter(playlist);
		TouchInterceptor listView = (TouchInterceptor)getListView();
		listView.setDropListener(this);
		listView.setRemoveListener(this);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		//update playlist from network
		
		playlist.add("File 1");
		
		System.out.println(getListView().getChildCount());
		
		playlist.add("File 2");
		playlist.add("File 3");
		playlist.add("File 4");
		playlist.add("File 5");
	}

	@Override
	public void drop(int from, int to) {
		if(from != to) {
			String object = playlist.getItem(from);
			playlist.remove(object);
			if(from > to) {
				playlist.insert(object, to);
			}else{
				playlist.insert(object, to-1);
			}
		}
	}

	@Override
	public void remove(int which) {
		playlist.remove(playlist.getItem(which));
	}

}
